import { getBaseUrl } from '@/services/urlconst';
import { getPosIDs, getUserID, getUserName, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';
const baseUrl = getBaseUrl();
/**
 * 办理流程
 * completeCallBack 回调
 */
const completeService = (completeCallBack: (res: any) => void, controller: string) => {
  const complete = useRequest(
    (params: any) => {
      const personUrl = `${baseUrl}/${controller}/complete`;
      let bodyParams = {
        ...params,
        // assigneeID: getUserID(),
        // assigneePositionID: getPosIDs(),
      };
      return requestFunComponFiex('PUT', personUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: completeCallBack,
    },
  );

  return {
    completeRun: complete?.run,
    completeLoading: complete?.loading,
  };
};

const batchCompleteService = (controller: string) => {
  const complete = useRequest(
    (params: any) => {
      const personUrl = `${baseUrl}/${controller}/complete`;
      let bodyParams = {
        ...params,
        // assigneeID: getUserID(),
        // assigneePositionID: getPosIDs(),
      };
      return requestFunComponFiex('PUT', personUrl, bodyParams);
    },
    {
      manual: true,
    },
  );

  return {
    batchCompleteRun: complete?.run,
    batchCompleteLoading: complete?.loading,
  };
};

/**
 * 流程帮办
 * resolveTaskCallBack 回调
 */
const resolveTaskService = (resolveTaskCallBack: (res: any) => void, controller: string) => {
  const resolveTask = useRequest(
    (params: any) => {
      const personUrl = `${baseUrl}/${controller}/resolveTask`;
      let bodyParams = {
        ...params,
        assigneeID: getUserID(),
      };
      return requestFunComponFiex('PUT', personUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: resolveTaskCallBack,
    },
  );

  return {
    resolveTaskRun: resolveTask?.run,
    resolveTaskLoading: resolveTask?.loading,
  };
};

/**
 * 合同作废
 * @param callback
 * @param controller
 * @returns
 */
const cancelTaskService = (callback: (res: any) => void, controller: string) => {
  const cancelTask = useRequest(
    (params: any) => {
      const personUrl = `${baseUrl}/${controller}/cancel`;
      let bodyParams = {
        ...params,
      };
      return requestFunComponFiex('PUT', personUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );

  return {
    cancelTaskRun: cancelTask?.run,
    cancelTaskLoading: cancelTask?.loading,
  };
};

export { completeService, resolveTaskService, cancelTaskService, batchCompleteService };
